package org.vt.ece3574.pictoslider.menus;

import org.vt.ece3574.pictoslider.R;

import yuku.ambilwarna.AmbilWarnaDialog;
import yuku.ambilwarna.AmbilWarnaDialog.OnAmbilWarnaListener;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

/**
 * Window which appears whenever the user selects "Custom" from the theme
 * spinner on the Settings Menu. This Activity allows the user to change the
 * background color of the Application and also change the Text color in the
 * Application.
 * 
 * @author Michael
 */
public class CustomThemeCreator extends Activity {

	/**
	 * The only text on the screen. This title's main purpose is to allow the
	 * user to see the effects of their choice of text color without having to
	 * leave the screen.
	 */
	private TextView title;
	/**
	 * Button which allows the user to change the background color of the app.
	 */
	private Button bgcolor;
	/**
	 * Button which allows the user to change the text color in the app.
	 */
	private Button txtcolor;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Themes.onActivityCreateSetTheme(this);
		Themes.onActivityCreateSetContentView(this,
				R.layout.custom_theme_creator);

		// Retreive the Activity Compenents from their Resource Id's.
		title = (TextView) findViewById(R.id.title);
		bgcolor = (Button) findViewById(R.id.backgroundcolor);
		txtcolor = (Button) findViewById(R.id.textcolor);

		// Set the View Parameters for the title TextView
		title.setTextColor(Themes.textColor(this));

		// Set the View Parameters for the bgcolor Button
		bgcolor.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// This Dialog allows the user to pick a custom color.
				new AmbilWarnaDialog(CustomThemeCreator.this,
						getSharedPreferences(SettingsMenu.SETTINGS_PREFS, 0)
								.getInt(Themes.BACKGROUND_COLOR, Color.BLACK),
						new OnAmbilWarnaListener() {
							public void onOk(AmbilWarnaDialog dialog, int color) {
								getSharedPreferences(
										SettingsMenu.SETTINGS_PREFS, 0).edit()
										.putInt(Themes.BACKGROUND_COLOR, color)
										.commit();
								Themes.changeToTheme(CustomThemeCreator.this,
										Themes.CUSTOM_POS);
							}

							public void onCancel(AmbilWarnaDialog dialog) {
							}
						}).show();
			}
		});

		// Set the View Parameters for the txtcolor Button
		txtcolor.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// This Dialog allows the user to pick a custom color.
				new AmbilWarnaDialog(CustomThemeCreator.this,
						getSharedPreferences(SettingsMenu.SETTINGS_PREFS, 0)
								.getInt(Themes.TEXT_COLOR, Color.WHITE),
						new OnAmbilWarnaListener() {
							public void onOk(AmbilWarnaDialog dialog, int color) {
								getSharedPreferences(
										SettingsMenu.SETTINGS_PREFS, 0).edit()
										.putInt(Themes.TEXT_COLOR, color)
										.commit();
								Themes.changeToTheme(CustomThemeCreator.this,
										Themes.CUSTOM_POS);
							}

							public void onCancel(AmbilWarnaDialog dialog) {
							}
						}).show();
			}
		});
	}
}
